package scene;

import org.netbeans.api.visual.action.ActionFactory;
import org.netbeans.api.visual.action.WidgetAction;
import org.netbeans.api.visual.anchor.AnchorFactory;
import org.netbeans.api.visual.anchor.AnchorShape;
import org.netbeans.api.visual.border.Border;
import org.netbeans.api.visual.border.BorderFactory;
import org.netbeans.api.visual.graph.GraphScene;
import org.netbeans.api.visual.widget.ConnectionWidget;
import org.netbeans.api.visual.widget.LayerWidget;
import org.netbeans.api.visual.widget.Widget;
import widget.EntidadeWidget;

/**
 * @author Slompo
 */
public class AmbienteModelagemDER extends GraphScene.StringGraph {

    private static final Border BORDER_FOUR = BorderFactory.createLineBorder(4);
    private final WidgetAction MOVE_ACTION = ActionFactory.createMoveAction();

    private LayerWidget mainLayer, connectionLayer, interractionLayer;
    
    public AmbienteModelagemDER() {
        mainLayer = new LayerWidget(this);
        addChild(mainLayer);
        
        connectionLayer = new LayerWidget(this);
        addChild(connectionLayer);
        
        
        interractionLayer = new LayerWidget(this);
        addChild (interractionLayer);
    }
    
    @Override
    protected Widget attachNodeWidget(String node) {
        EntidadeWidget ew = new EntidadeWidget(this, node);
        ew.addPK(ew.createPK("ID"+node));
        ew.addOther(ew.createFK("xnajxnjanjxanjxn"));
        ew.addOther(ew.createOther("hahahaha"));
        
        WidgetAction resizeAction = ActionFactory
                .createAlignWithResizeAction(mainLayer, interractionLayer, null, false);
        
        ew.getActions().addAction(MOVE_ACTION);
        ew.getActions().addAction(resizeAction);
        mainLayer.addChild(ew);
        
        return ew;
    }

    @Override
    protected Widget attachEdgeWidget(String e) {
        ConnectionWidget cw = new ConnectionWidget(this);
        cw.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED);
        connectionLayer.addChild(cw);
        return cw;
    }

    @Override
    protected void attachEdgeSourceAnchor(String edge, String oldSourceNode, String sourceNode) {
        Widget w = sourceNode != null ? findWidget(sourceNode) : null;
        ConnectionWidget cw = (ConnectionWidget) findWidget(edge);
        cw.setSourceAnchor(AnchorFactory.createRectangularAnchor(w));
    }

    @Override
    protected void attachEdgeTargetAnchor(String edge, String oldTargetNode, String targetNode) {
        Widget w = targetNode != null ? findWidget(targetNode) : null;
        ConnectionWidget cw = (ConnectionWidget) findWidget(edge);
        cw.setTargetAnchor(AnchorFactory.createRectangularAnchor(w));
    }
    
}
